#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int sss=0,www=1;
	char chh=getchar();
	while(chh<'0'||chh>'9'){
		if(chh=='-') www=-1;
		chh=getchar();
	}
	while(chh>='0'&&chh<='9'){
		sss=sss*10+chh-'0';
		chh=getchar();
	}
	return sss*www;
}
int n;
struct node{
	int a,b,sum;
}p[100005];
bool cmp(const node& x,const node& y){
	if(x.b==y.b) return x.sum<y.sum;
	return x.b<y.b;
}
signed main(){
	freopen("boast.in","r",stdin);
	freopen("boast.out","w",stdout);
	n=read(); int ans=1e15;
	for(register int i=1;i<=n;i++){
		p[i].a=read(),p[i].b=read();
		p[i].sum=p[i].a+p[i].b;
	}
	sort(p+1,p+n+1,cmp);
	set<int> s;
	for(register int i=n;i>=1;i--){
		if(s.size()>=2){
			set<int>::iterator it=s.begin();
			int num1=*it; it++;
			int num2=*it;
			ans=min(ans,num1+num2+p[i].a);
		}
		s.insert(p[i].sum);
	}
	cout<<ans;
	return 0;
}
